package configer;

import cn.hutool.json.JSONObject;
import common.Const;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Properties;

public class SqlServerConfiger {
    protected final static Logger logger = LoggerFactory.getLogger(SqlServerConfiger.class);         // 日志对象

    // 数据库
    private String sqlServer_address;         // 数据库IP地址
    private int sqlServer_port;            // 数据库访问端口
    private String sqlServer_account;         // 数据库访问账户
    private String sqlServer_password;        // 数据库账户密码
    private String sqlServer_database;        // 数据库名称
    private String sqlServer_schema;          // 模式
    private String sqlServer_tableName;       // 数据表名称

    // head 内容
    private String dataUser;        // 元数据所有者
    private String dataName;        // 元数据名称
    private String dataType;        // 数据类型
    private String dataIndexs;      // 数据索引表
    private String dataFlag;        // 上链模式
    private String dataCrypt;       // 加密方式
    private int dataLevel;       // 数据级别

    // rocketmq 配置信息
    private String nameSrv;   // NameSrv地址
    private String topicName;      // Topic名称
    private String tagName;        // Tag名称
    private String producerGroup;  // 生产者组

    public SqlServerConfiger(String tableName, JSONObject result, Properties properties) {
        sqlServer_account = properties.getProperty("sqlServer_account");
        sqlServer_password = properties.getProperty("sqlServer_password");
        sqlServer_address = properties.getProperty("sqlServer_address");
        sqlServer_database = properties.getProperty("sqlServer_database");
        sqlServer_schema = properties.getProperty("sqlServer_schema");
        this.sqlServer_tableName = tableName;
        sqlServer_port = "".equals(properties.getProperty("sqlServer_port")) ? Const.SQLSERVER_DATABASE_PORT : Integer.parseInt(properties.getProperty("sqlServer_port"));

        // 解析元数据
        dataUser = result.getStr("account") != null ? result.getStr("account") : properties.getProperty("sqlServer_dataUser");
        dataName = result.getStr("dataName") != null ? result.getStr("dataName") : properties.getProperty("dataName");
        dataType = result.getStr("dataType") != null ? result.getStr("dataType") : properties.getProperty("dataType");
        dataIndexs = result.getStr("dataIndexs") != null ? result.getStr("dataIndexs") : properties.getProperty("dataIndexs");
        dataFlag = result.getStr("dataFlag") != null ? result.getStr("dataFlag") : properties.getProperty("dataFlag");
        dataCrypt = result.getStr("dataCrype") != null ? result.getStr("dataCrype") : properties.getProperty("dataCrypt");
        dataLevel = result.getInt("dataLevel") != null ? result.getInt("dataLevel") : Integer.parseInt(properties.getProperty("dataLevel"));

        nameSrv = "".equals(properties.getProperty("nameSrv")) ? Const.DEFAULT_NAME_SRV_ADD : properties.getProperty("nameSrv");
        topicName = "".equals(properties.getProperty("topicName")) ? Const.DEFAULT_TOPIC_NAME : properties.getProperty("topicName");
        tagName = "".equals(properties.getProperty("tagName")) ? Const.DEFAULT_TAG_NAME : properties.getProperty("tagName");
        producerGroup = "".equals(properties.getProperty("producerGroup")) ? Const.DEFAULT_PRODUCER_GROUP : properties.getProperty("producerGroup");

        logger.info("SqlServerConfiger 对象初始化完毕！");

    }


    public String getSqlServer_address() {
        return sqlServer_address;
    }

    public int getSqlServer_port() {
        return sqlServer_port;
    }

    public String getSqlServer_account() {
        return sqlServer_account;
    }

    public String getSqlServer_password() {
        return sqlServer_password;
    }

    public String getSqlServer_database() {
        return sqlServer_database;
    }

    public String getSqlServer_schema() {
        return sqlServer_schema;
    }

    public String getSqlServer_tableName() {
        return sqlServer_tableName;
    }

    public String getDataUser() {
        return dataUser;
    }

    public String getDataName() {
        return dataName;
    }

    public String getDataType() {
        return dataType;
    }

    public String getDataIndexs() {
        return dataIndexs;
    }

    public String getDataFlag() {
        return dataFlag;
    }

    public String getDataCrypt() {
        return dataCrypt;
    }

    public int getDataLevel() {
        return dataLevel;
    }

    public String getNameSrv() {
        return nameSrv;
    }

    public String getTopicName() {
        return topicName;
    }

    public String getTagName() {
        return tagName;
    }

    public String getProducerGroup() {
        return producerGroup;
    }
}
